package com.hzdesk.media.matvector.koreabatch.client.my_paperless.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hzdesk.media.matvector.koreabatch.client.my_paperless.R;



/**
 * Created by Administrator on 2018/8/8.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public abstract class BaseFragment extends Fragment {
    public Context mContext;
    ImageView myBaseRlTileIvLeft;
    TextView myBaseRlTileTvTile;
    ImageView myBaseRlTileIvRight;
    TextView myBaseRlTileTvRight;
    RelativeLayout myBaseRlTile;
    FrameLayout baseFragmentRlView;
    private View myChildFragmentView;
    private RelativeLayout my_base_rl_tile;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mContext = context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.base_fragment, container, false);
        findView(view);
        return view;
    }

    private void findView(View view) {
        myBaseRlTileIvLeft = view.findViewById(R.id.my_base_rl_tile_iv_left);
        myBaseRlTileTvTile = view.findViewById(R.id.my_base_rl_tile_tv_tile);
        myBaseRlTileIvRight = view.findViewById(R.id.my_base_rl_tile_iv_right);
        myBaseRlTileTvRight = view.findViewById(R.id.my_base_rl_tile_tv_right);
        my_base_rl_tile = view.findViewById(R.id.my_base_rl_tile);
        myBaseRlTile = view.findViewById(R.id.my_base_rl_tile);
        baseFragmentRlView = view.findViewById(R.id.base_fragment_rl_view);

        setOnclikedLinstener(myBaseRlTileIvLeft,0);
        setOnclikedLinstener(myBaseRlTileIvRight,1);
        setOnclikedLinstener(myBaseRlTileTvRight,2);
        myChildFragmentView = getChildFragmentView();
        if(myChildFragmentView != null){
            baseFragmentRlView.addView(myChildFragmentView);
        }


    }
    public void setOnclikedLinstener(View view, final int type){
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (type){
                    case 0:
                        onClickedIvLeft();
                        break;
                    case 1:
                        onClickedIvRight();
                        break;
                    case 2:
                        onClickedTvRight();
                        break;
                }
            }
        });
    }

    @Override
    public void onStart() {
        super.onStart();

        initDate();
    }


    @Override
    public void onDestroyView() {
        if(myChildFragmentView != null){
            baseFragmentRlView.removeView(myChildFragmentView);
            myChildFragmentView = null;
        }
        cancellationControls();
        super.onDestroyView();
    }

    // 注销控件
    protected abstract void cancellationControls();


    // 初始化数据
    protected abstract void initDate();
    // 添加试图
    protected abstract View getChildFragmentView();
    // 点击 左边的图标
    protected abstract void onClickedTvRight();
    // 点击 右边的图标
    protected abstract void onClickedIvRight();
    // 点击 右边的文字
    protected abstract void onClickedIvLeft();
    //-------------------左边的图标------------------------------------------------------------------
    /**
     * @desc 显示标题栏左边的图标 一般是返回图标
     * */
    public void showTileIvLeft(){
        myBaseRlTileIvLeft.setVisibility(View.VISIBLE);
    }
    /**
     * @desc 隐藏标题栏左边的图标 一般是返回图标
     * */
    public void hiddenTileIvLeft(){
        myBaseRlTileIvLeft.setVisibility(View.GONE);
    }
    /**
     * @desc 设置标题栏左边的图标 一般是返回图标
     * @param resIcon 图标引用
     * */
    public void setIvLeftIcon(int resIcon){
        myBaseRlTileIvLeft.setBackgroundResource(resIcon);
    }

    //-------------------右边的图标------------------------------------------------------------------
    /**
     * @desc 显示标题栏右边的图标
     * */
    public void showTileIvRight(){
        myBaseRlTileIvRight.setVisibility(View.VISIBLE);
    }
    /**
     * @desc 隐藏标题栏右边的图标
     * */
    public void hiddenTileIvRight(){
        myBaseRlTileIvRight.setVisibility(View.GONE);
    }
    /**
     * @desc 设置标题栏右边的图标
     * @param resIcon 图标引用
     * */
    public void setIvLeftRight(int resIcon){
        myBaseRlTileIvRight.setBackgroundResource(resIcon);
    }


    //-------------------title背景色-----------------------------------------------------------------
    /**
     * @desc 显示title的文字
     * */
    public void showTilteBg(){
        myBaseRlTile.setVisibility(View.VISIBLE);
    }
    /**
     * @desc 隐藏title的文字
     * */
    public void hiddenTilteBg(){
        myBaseRlTile.setVisibility(View.GONE);
    }
    /**
     * @desc 修改 title背景色
     * */
    public void setTilteBgColor(int resColor){
        myBaseRlTile.setBackgroundResource(resColor);
    }


    //-------------------title-----------------------------------------------------------------
    /**
     * @desc 显示title的文字
     * */
    public void showTitleContent(){
        myBaseRlTileTvTile.setVisibility(View.VISIBLE);
    }
    /**
     * @desc 隐藏title的文字
     * */
    public void hiddenTitleContent(){
        myBaseRlTileTvTile.setVisibility(View.GONE);
    }
    /**
     * @desc 设置标题的颜色和内容
     * @param text   标题的内容
     * @param resColor  标题的颜色
     * */
    public void setTitleContent(String text,int resColor){
        myBaseRlTileTvTile.setText(text);
        myBaseRlTileTvTile.setTextColor(resColor);
    }
    /**
     * @desc 设置标题的大小
     * */
    public void setTitleContentSize(int seze){
        myBaseRlTileTvTile.setTextSize(seze);
    }

    //-------------------title右边的文字-------------------------------------------------------------
    /**
     * @desc 显示title右边的文字
     * */
    public void showTilteRightContent(){
        myBaseRlTileTvRight.setVisibility(View.VISIBLE);
    }
    /**
     * @desc 隐藏title右边的文字
     * */
    public void hiddenTilteRightContent(){
        myBaseRlTileTvRight.setVisibility(View.GONE);
    }
    /**
     * @desc 设置标题右边的文字的颜色和内容
     * @param text   标题的内容
     * @param resColor  标题的颜色
     * */
    public void setTilteRightContent(String text,int resColor){
        myBaseRlTileTvRight.setText(text);
        myBaseRlTileTvRight.setTextColor(resColor);
    }
    /**
     * @desc 设置标题右边的文字的大小
     * */
    public void setTitleRightContentSize(int seze){
        myBaseRlTileTvRight.setTextSize(seze);
    }

    //==============================================================================
    /**
     * @desc 显示标题栏左边的图标 一般是返回图标
     * */
    public void showTileTitleRlBg(){
        myBaseRlTile.setVisibility(View.VISIBLE);
    }
    /**
     * @desc 隐藏标题栏左边的图标 一般是返回图标
     * */
    public void hiddenTileTitleRlBg(){
        myBaseRlTile.setVisibility(View.GONE);
    }
    /**
     * @desc 跳转页面
     */
    public void toPageJump(Class<?> cls) {
        startActivity(new Intent(mContext, cls));
    }
}
